#pragma once

#include "Timestamp.h"
#include "noncopyable.h"

#include<vector>
#include<unordered_map>

class Channel;
class EventLoop;
// muduo库中 多路事件分发器的I/O复用模块


class Poller: noncopyable
{
public: 
    using ChannelList = std::vector<Channel*>;

    Poller(EventLoop* loop);
    virtual ~Poller()=default;

    // 给所有I/O复用保留统一接口来重写
    virtual Timestamp poll(int timeoutMs, ChannelList* activeChannels) = 0;
    virtual void updateChannel(Channel* channel) = 0;
    virtual void removeChannel(Channel* channel) = 0;

    // 判断当前channel是否在当前Poller中
    bool hasChannel(Channel* channel) const;

    // EventLoop通过该接口 获取默认I/O复用的具体实现
    static Poller* newDefaultPoller(EventLoop* loop);
protected:
    // map的key：sockfd value：sockfd所属的channel通道类型
    using ChannelMap = std::unordered_map<int,Channel*>;
    ChannelMap channels_;

private:
    EventLoop* owenerLoop_; // 定义Poller所属的事件循环EventLoop



};